<template>
	<view class="pl52 pr52">
		<view class="fs58 fw mt40">注册</view>
		<view class="mobilebox pl40 mt70">
			<u-input v-model="query.mobile" type="number" :border="false" height="90" placeholder="请输入手机号" />
		</view>
		
		<view class="pwdbox pl40 mt30 flex col-center pr26">
			<u-input v-model="query.code" type="number" :border="false" height="90" placeholder="请输入验证码" />
			<text @tap="getCode" class="color-y fs26">{{tips}}</text>
		</view>

		<view class="pwdbox pl40 mt30 flex col-center pr30">
			<u-input v-model="query.loginpass" type="password" :border="false" height="90"
				placeholder="请设置登录密码" />
		</view>

		<view class="pwdbox pl40 mt30 flex col-center pr30">
			<u-input v-model="query.quepass" type="password" :border="false" height="90" placeholder="请确认登录密码" />
		</view>
		
		<view class="pwdbox pl40 mt30 flex col-center">
			<u-input v-model="query.id_card" type="text" :border="false" height="90" placeholder="请输入身份证号" />
		</view>
		
		<view class="pwdbox pl40 mt30 flex col-center">
			<u-input v-model="query.regcode"  :border="false" height="90" placeholder="请输入邀请码" />
		</view>

		<view class="loginbox mt50" >
			<u-button type="primary" shape="circle" @click='submit'>注册</u-button>
		</view>
		<view class="fs24 color9 flex row-center mt50 col-center">
			<label class="radio">
				<radio :checked="flag" @click="flag=!flag" color="#FF6B35"/><text></text>
			</label>
			<text>点击按钮即表示您同意并愿意准守</text>
		</view>
		<view class="flex row-center col-center color9">
			<navigator class="fs24 color-y flex row-center mt20" url="/pages/login/xieyi?from=1">
				《注册协议》
			</navigator>
			<text class="fs24 flex row-center mt20">和</text>
			<navigator class="fs24 color-y flex row-center mt20" url="/pages/login/xieyi?from=2">
				《隐私政策》
			</navigator>
		</view>
		<u-verification-code :seconds="seconds" ref="uCode" @change="codeChange">
		</u-verification-code>
	</view>
</template>

<script>
	export default {
		onLoad(opt) {
			if(opt.regcode) {
				this.query.regcode=opt.regcode
				this.from=opt.from
			}
		},
		data() {
			return {
				tips: '',
				seconds: 60,
				query: {
					mobile: '',
					code: '',
					loginpass: '',
					// 确认密码
					quepass: '',
					regcode: '',
					id_card:''
				},
				flag:false,
				//from==1来自与海报
				from:''
			};
		},
		methods: {
			//提交注册
			submit() {
				if(this.flag) {
					if(this.query.loginpass!=this.query.quepass) {
						this.$msg('两次输入的密码不一致,请检查后重新输入')
						return
					}
					this.$api.register(this.query).then(res=>{
						this.$msg(res.msg)
						if(this.from==1) {
							setTimeout(()=>{
								window.open('http://gw.beiyuansm.com/download')
							},500)
						}else {
							setTimeout(()=>{
								uni.navigateBack({
									
								})
							},800)
						}
						
					})
				}else {
					this.$msg('您未勾选注册以及隐私协议')
				}
				
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$api.send_sms({
						mobile: this.query.mobile,
						type:'register'
					}).then(res => {
						console.log(res)
						if(res.code==1) {
							this.$u.toast('验证码已发送');
							this.$refs.uCode.start();
						}
					})
					// setTimeout(() => {
					// 	uni.hideLoading();
					// 	// 这里此提示会被this.start()方法中的提示覆盖
					// 	this.$u.toast('验证码已发送');
					// 	// 通知验证码组件内部开始倒计时
					// 	this.$refs.uCode.start();
					// }, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			//前往使用协议
			gotoUse() {
				// window.location.href='http://www.fmcgzn.com/h5/#/subpkg/xieyi/xieyi?from=1'
				uni.navigateTo({
					url:'/login/xieyi/xieyi?from=1'
				})
			}
			// end() {
			// 	this.$u.toast('倒计时结束');
			// },
			// start() {
			// 	this.$u.toast('倒计时开始');
			// }
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.mobilebox,
	.pwdbox {
		width: 100%;
		height: 90rpx;
		background: #F8F8F8;
		border-radius: 50rpx;

	}

	.loginbox {
		width: 100%;
		height: 90rpx;
		border-radius: 50rpx;
		font-size: 30rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 90rpx;
		font-weight: 700;
	}
</style>
